﻿using System.Collections.Generic;
using Castle.Facilities.FactorySupport;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using NUnit.Framework;

namespace WindsorInitConfig {
    [TestFixture]
    public class EnumerableRegistration {
        [Test]
        public void Bug() {
            var container = new WindsorContainer();
            container.AddFacility<FactorySupportFacility>();
            container.Register(Component.For<IService>
                                   ().ImplementedBy<Service1>().Named("1"));
            container.Register(Component.For<IService>
                                   ().ImplementedBy<Service2>().Named("2"));
            container.Register(Component.For<IEnumerable<IService>>
                                   ().UsingFactoryMethod(() => container.ResolveAll<IService>()));
            container.Register(Component.For<Consumer>());
            Assert.IsNotNull(container.Kernel.Resolve<Consumer>());
        }

        public class Consumer {
            public Consumer(IEnumerable<IService> services) {}
        }

        public class Service1 : IService {}

        public class Service2 : IService {}

        public interface IService {}
    }
}